Skip to content

Avoid rooting cryptography through ZipArchive on browser - #130688

Open
alinpahontu2912 with Copilot wants to merge 12 commits into
mainfrom
copilot/fix-ziparchive-password-support
Open

Avoid rooting cryptography through ZipArchive on browser#130688
alinpahontu2912 with Copilot wants to merge 12 commits into
mainfrom
copilot/fix-ziparchive-password-support

Conversation

Copilot AI commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Fixes #130650
which is regression from #122093

Using ZipArchive on browser-wasm unnecessarily retained System.Security.Cryptography, increasing trimmed application size even though WinZip AES is unsupported there.

Changes

  • Exclude WinZip AES implementation files and the cryptography project reference from browser builds.
  • Provide browser-specific WinZip AES stubs that continue throwing PlatformNotSupportedException.
  • Keep ZipCrypto supported by removing its cryptography dependency:
    • Generate header randomness with Guid.NewGuid().
    • Clear pooled password buffers with Array.Clear.
  • Add coverage ensuring browser ZipCrypto remains functional and the wasm dependency closure excludes System.Security.Cryptography.

Copilot AI and others added 2 commits July 14, 2026 13:30
Co-authored-by: alinpahontu2912 <56953855+alinpahontu2912@users.noreply.github.com>
Co-authored-by: alinpahontu2912 <56953855+alinpahontu2912@users.noreply.github.com>
Copilot AI self-assigned this Jul 14, 2026
Copilot AI review requested due to automatic review settings July 14, 2026 14:01
Copilot AI removed the request for review from Copilot July 14, 2026 14:01
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.

@pavelsavara
pavelsavara temporarily deployed to copilot-pat-pool July 15, 2026 08:28 — with GitHub Actions Inactive
Co-authored-by: alinpahontu2912 <56953855+alinpahontu2912@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot July 15, 2026 08:34
Co-authored-by: alinpahontu2912 <56953855+alinpahontu2912@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot July 15, 2026 08:48
Co-authored-by: alinpahontu2912 <56953855+alinpahontu2912@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot July 15, 2026 08:53
Co-authored-by: alinpahontu2912 <56953855+alinpahontu2912@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 31, 2026 07:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

Co-authored-by: alinpahontu2912 <56953855+alinpahontu2912@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 31, 2026 08:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Suppressed comments (1)

src/libraries/System.IO.Compression/src/System/IO/Compression/WinZipAes.PlatformNotSupported.cs:9

  • WinZipAesKeyMaterial is declared with a trailing ; (a forward declaration), which is not valid C# syntax and will fail compilation for browser TFMs. Define an empty struct body instead so the browser stub can satisfy references from the rest of the ZIP code.
    internal readonly struct WinZipAesKeyMaterial;

Comment on lines 136 to 142
}
}
finally
{
CryptographicOperations.ZeroMemory(passwordBytes);
Array.Clear(passwordBytes);
ArrayPool<byte>.Shared.Return(passwordBytes);
}
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.

Suppressed comments (2)

src/libraries/System.IO.Compression/src/System/IO/Compression/WinZipAes.PlatformNotSupported.cs:9

  • internal readonly struct WinZipAesKeyMaterial; is not valid C# syntax (C# doesn't support forward declarations). This will fail to compile the browser target. Define an (empty) struct type instead so the rest of the code can reference it.
    internal readonly struct WinZipAesKeyMaterial;

src/libraries/System.IO.Compression/src/System/IO/Compression/ZipCryptoStream.Random.BrowserOrWasi.cs:18

  • PR description says ZipCrypto header randomness is generated with Guid.NewGuid(), but the implementation uses Interop.Sys.GetCryptographicallySecureRandomBytes on browser/wasi (and RandomNumberGenerator.Fill elsewhere). Please update the PR description (or code) so the documented approach matches what actually shipped.
            // System.Security.Cryptography's RandomNumberGenerator is not referenced on browser and is
            // not supported on wasi, so call the shared native CSPRNG directly. It is backed by
            // crypto.getRandomValues() on browser and by wasi:random (getentropy/__wasi_random_get) on wasi.
            Span<byte> randomBytes = header.Slice(0, 10);
            fixed (byte* pRandomBytes = randomBytes)
            {
                if (Interop.Sys.GetCryptographicallySecureRandomBytes(pRandomBytes, randomBytes.Length) != 0)
                {
                    throw new IOException(SR.UnableToGenerateRandomBytes);

…atforms

Co-authored-by: alinpahontu2912 <56953855+alinpahontu2912@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 31, 2026 10:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

@@ -0,0 +1,13 @@
// Licensed to the .NET Foundation under one or more agreements.

@pavelsavara pavelsavara Jul 31, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead reuse it

   <Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetRandomBytes.cs"
             Link="Common\Interop\Unix\System.Native\Interop.GetRandomBytes.cs" />

@pavelsavara pavelsavara Jul 31, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think with Interop.GetCryptographicallySecureRandomBytes you can drop crypto assembly dependency on all platforms, not just browser and have unified code.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the cryptography dependency is still preferred. It provides a clearer abstraction, avoids exposing interop details, and keeps the implementation consistent with the rest of .NET. I'd rather find an acceptable browser-specific alternative for ZipCrypto to address the size regession than switch everything over to Interop.GetCryptographicallySecureRandomBytes.

Co-authored-by: alinpahontu2912 <56953855+alinpahontu2912@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 31, 2026 12:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-System.IO.Compression os-browser Browser variant of arch-wasm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[wasm] System.IO.Compression roots System.Security.Cryptography into every trimmed app using ZipArchive (size regression from #122093)

6 participants